package com.evil.common.application.dto.judge;

import cn.hutool.core.collection.CollUtil;
import com.evil.common.application.enums.judge.JudgeSignEnum;
import com.evil.common.application.enums.judge.MatchingTypeEnum;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * 条件实体
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@Data
public class Judge {

    private Long judgeId;

    /**
     * 表单控件id
     */
    private Long controlId;

    /**
     * 控件code
     */
    private String controlCode;

    /**
     * 判断符号，0:等于, 1:不等于, 2:包含, 3:不包含, 4:属于, 5:不属于
     */
    private Integer judgeSign;

    /**
     * 匹配类型（默认值自定义）{@link MatchingTypeEnum}
     */
    private Integer matchingType;

    /**
     * 目标id（matching_type=2时有值）
     */
    private Long targetId;

    /**
     * 筛选值
     */
    private List<String> values;

    /**
     * 上级条件id（且条件时 值有效）
     */
    private Long parentJudgeId;

    public Judge() {
        this.controlId = 0L;
        this.controlCode = "";
        this.judgeSign = JudgeSignEnum.EQUALS.getId();
        this.matchingType = MatchingTypeEnum.CUSTOM.getId();
        this.targetId = 0L;
        this.values = new ArrayList<>();
    }

    public Judge(Long controlId, String controlCode, JudgeSignEnum judgeSignEnum, String... value) {
        this.controlId = controlId;
        this.controlCode = controlCode;
        this.judgeSign = judgeSignEnum.getId();
        this.matchingType = MatchingTypeEnum.CUSTOM.getId();
        this.targetId = 0L;
        this.values = CollUtil.toList(value);
    }

    public Judge addValue(String value) {
        this.values.add(value);
        return this;
    }
}
